/* $Id: WidgetCategory.java 52 2010-01-11 01:42:30Z aaron.day $ */
package org.crazydays.gameplan.widget;


import java.io.Serializable;

/**
 * WidgetCategory
 */
public class WidgetCategory
    implements Serializable, Comparable<WidgetCategory>
{
    /** serial version uid */
    public final static long serialVersionUID =
        "$Id: WidgetCategory.java 52 2010-01-11 01:42:30Z aaron.day $"
            .hashCode();

    /** name */
    protected String name;

    /** description */
    protected String description;

    /**
     * WidgetCategory constructor.
     */
    public WidgetCategory()
    {
    }

    /**
     * WidgetCategory constructor.
     * 
     * @param name Name
     * @param description Description
     */
    public WidgetCategory(String name, String description)
    {
        setName(name);
        setDescription(description);
    }

    /**
     * Set name.
     * 
     * @param name Name
     */
    public final void setName(String name)
    {
        this.name = name;
    }

    /**
     * Get name.
     * 
     * @return Name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Set description.
     * 
     * @param description Description
     */
    public final void setDescription(String description)
    {
        this.description = description;
    }

    /**
     * Get description.
     * 
     * @return Description
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * Categories are equal when name is the same.
     * 
     * @param o Object
     * @return Equal
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object o)
    {
        if (!(o instanceof WidgetCategory)) {
            return false;
        }

        WidgetCategory category = (WidgetCategory) o;

        if (getName() == null || category.getName() == null) {
            if (getName() != null) {
                return false;
            }
            if (category.getName() != null) {
                return false;
            }
        }

        if (!getName().equals(category.getName())) {
            return false;
        }

        return true;
    }

    /**
     * Get name.
     * 
     * @return Name
     * @see Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        if (getName() == null) {
            return 0;
        } else {
            return getName().hashCode();
        }
    }

    /**
     * Categories are alphabetical by name.
     * 
     * @param category Category
     * @return Comparison
     * @see Comparable#compareTo(Object)
     */
    @Override
    public int compareTo(WidgetCategory category)
    {
        if (equals(category)) {
            return 0;
        }

        if (getName() == null) {
            return -1;
        } else {
            return getName().compareTo(category.getName());
        }
    }
}
